package logic

import (
	"context"
	"person/personrpc/personrpc"

	"person/personapi/internal/svc"
	"person/personapi/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type PersonUpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewPersonUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PersonUpdateLogic {
	return &PersonUpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *PersonUpdateLogic) PersonUpdate(req *types.PersonUpdateRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	update, err := l.svcCtx.PersonRpc.UserUpdate(l.ctx, &personrpc.UserUpdateRequest{
		Userid: int64(req.UserId),
		Name:   req.Name,
		Price:  int64(req.Price),
		Class:  req.Class,
		Id:     int64(req.Id),
	})
	if err != nil {
		return &types.Response{
			Message: "修改失败",
			Code:    "500",
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "修改成功",
		Code:    "200",
		Data:    update,
	}, nil
}
